package com.hao.springcloud.controller;

import com.hao.springcloud.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class DeptConsumerController {
    @Autowired
    private RestTemplate restTemplate;
/*    private static final String REXT_URL_PREFIX="http://localhost:8001";*/
    private static final String REXT_URL_PREFIX= "springcloud-provider-service";
    @RequestMapping("/consumer/dept/add")
    public boolean add(Dept dept){
        return restTemplate.postForObject(REXT_URL_PREFIX+"/dept/add",dept,boolean.class);
    }
    @RequestMapping("/consumer/dept/getdept/{id}")
    public Dept getDeptById(long id){
        return restTemplate.getForObject(REXT_URL_PREFIX+"/dept/get/"+id,Dept.class);
    }
    @RequestMapping("/consumer/dept/getAll")
    public List<Dept> getAll(){
        return restTemplate.getForObject(REXT_URL_PREFIX+"/dept/getAll",List.class);
    }
}
